home *** CD-ROM | disk | FTP | other *** search
- DIRSCAN - Scan a disk directory - V1.0
-
- Summary
-
- #include dirscan.h
- long dirscan(directory,file_mask,attrib_mask,dir_exit,file_exit);
-
- char directory[];
- char file_mask[];
- char attrib_mask;
- void (* dir_exit) (char[]);
- void (* file_exit)(char[],struct find_t);
-
- Description
-
- Searches a disk directory structure for all files matching the
- file-name and extension contained in 'file_mask'. The
- arguments to dirscan are:
-
- char directory[] (or char * directory)
-
- A null-terminated string that contains the starting path
- for the directory search. Dirscan will scan the specified
- directory and all its sub-directories to their maximum
- depth.
-
- char file_mask[] (or char * file_mask)
-
- A null-terminated string that contains a standard DOS
- file-name mask (i.e. possibly containing '*' and '?').
- Dirscan will 'find' only files that match the specified
- file mask.
-
- char attrib_mask
-
- A single byte (not a pointer) that can have bits set to
- indicate that dirscan is to 'find' SYSTEM and/or HIDDEN
- files in addition to normal files. If the attrib_mask is
- 0x00, dirscan will 'find' only normal files. If in
- addition you want to find SYSTEM files, turn on the 0x02
- bit. To 'find' HIDDEN files, turn on the 0x04 bit. The
- Microsoft C compiler provides preprocessor variables
- _A_SYSTEM and _A_HIDDEN for this purpose. The remainder
- of the bits in attrib_mask will be ignored.
-
- void (* dir_exit) (char[])
- void (* file_exit) (char[], struct find_t)
-
- Dirscan is a general-purpose utility and does not perform
- any processing on the files it finds. Instead, it calls
- one of two routines that you provide to it. The fourth
- and fifth arguments to dirscan are pointers to two 'exit'
- routines that dirscan calls for each directory and file
- that match the specified path and file-mask. "dir_exit"
- points to a routine that dirscan will call as it begins to
- scan a given subdirectory. Normally this routine will be
- used to display status information or keep track of where
- dirscan is currently looking. The pointer can be NULL, in
- which case dirscan will bypass the directory exit call.
-
- The fifth parameter "file_exit" contains a pointer to a
- subroutine that dirscan will call once for each file it
- finds that matches the specified file-mask and
- attrib-mask. This routine is used to perform any required
- processing. For example, when using dirscan to implement
- a "file-find" program, the file_exit routine would display
- the name of the file and probably its size and timestamp.
- The pointer can be NULL, in which case no file_exit
- routine will be called.
-
- Exit Routine Interface
-
- To use dirscan you must provide two exit routines to handle
- subdirectories and files. You can do this by defining the
- routines in the module that calls dirscan. When you call
- dirscan, pass the addresses of the routines as the fourth and
- fifth arguments. Note that to pass a function pointer to a
- subroutine you merely specify the name of the function to be
- passed in the argument list... no leading '&' is required,
- thus:
-
- dirscan( .....,dir_exit,file_exit);
-
- The exit routines must accept the following arguments:
-
- dir_exit (char *)
-
-
- The dir_exit routine is called once for each new
- directory examined. It is passed a pointer to a
- null-terminated string that contains the current
- path-name of the sub-directory being examined. It is
- called BEFORE any files in the directory are examined.
-
- file_exit (char *,struct find_t)
-
- The file_exit routine is called once for each file
- that matches the specified file_mask and attrib_mask.
- The first argument to file_exit is the current
- sub-directory path name. The second is the work
- buffer used by the DOS "find-first" and "find-next"
- routines to return directory information. This
- structure is usually defined in <dos.h>.
-
- To facilitate mapping of the file date and time contained in
- (struct find_t), two structure data types (typedefs) are
- provide in "dirscan.h", FILE_TIME and FILE_DATE. These
- structures can be overlaid on the file time and date fields in
- (struct find_t) to extract the bit fields representing the
- various components of the time and date. There is an example
- of this in the file_exit routine in "locate.c".
-
- Return Values
-
- The dirscan function returns the total number of files
- present in the directory structure below the starting path
- name. This is NOT the number of 'found' files... it is the
- number of files that would have been found had the file_mask
- contained "*.*".
-
- Usage Note
-
- dirscan deals with the variable depth of the directory tree
- structure by calling itself recursively. Since dirscan uses
- about 160 bytes of stack space, you may run into stack
- overflow when using your compiler's default stack allocation
- with a highly structured directory (many levels deep). If
- this happens, increase the default stack size.
-
- Example
-
- This ARC file contains a complete example of how to use
- dirscan called "locate.c", which implements a "find-file"
- utility routine. The LOCATE command has the following syntax:
-
- LOCATE [d:][\dir\dir....\][file-name][.[ext]]
-
- All path components are optional and default as follows if
- not specified:
-
- d: The currently logged drive
- \dir... \ (root directory)
- file-name *
- ext .*
-
- Note that entering a filename without an extension is
- equivalent to providing a ".*" extension. To search for
- occurrences of a filename with no extension you must follow
- the filename with a period. For example:
-
- LOCATE README is interpreted as LOCATE README.*
-
- To find files called "README" with no extension, enter
-
- LOCATE README.
-
- Disclaimer
-
- The source code included here is placed in the public domain
- and distributed AS-IS. No .OBJ or .EXE files are included.
- You must create them by compiling and linking the provided C
- source code. You are fully responsible for the results of
- compiling and using these routines in your programs, and I
- will assume no liability for damages, consequential or
- otherwise.
-
- Dirscan was implemented and tested under PC-DOS 3.3 with the
- Microsoft C 5.1 compiler. Since it uses DOS interface
- routines (find-first, find-next) it will probably not compile
- under a different compiler without modification.
-
- Jim Garrison -- 76247,1747